<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax查询页</title>
<script type="text/javascript"  src="./static/js/jquery.min.js"></script>
</head>
<body>
<a href="insert.html">添加</a>
	<table border="1">
		<tr>
			<th>编号</th>
			<th>姓名</th>
			<th>年龄</th>
			<th>薪资</th>
			<th>入职日期</th>
			<th>操作</th>
		</tr >
       <tbody id="t" ></tbody>
	</table>

	<script>
		$(document).ready(
				function() {
					
					var tbody=window.document.getElementById("t"); 
					$.ajax({
						type : "GET",
						dataType : "json",
						url : "employee/employee",
						/* error : function(data) {
							alert("error" + data)
						}, */
						success : function(data) {
                 		 var str ="";
							for (i in data) {
								//时间转换
								var da = data[i].hireDate;
							    da = new Date(da);
							    var year = da.getFullYear();
							    var month = da.getMonth()+1;
							    var day = da.getDate();
							    var hireDate= [year,month,day].join('-');										
										str +=( "<tr>" + "<td>" + data[i].id + "</td>"
												+ "<td>" + data[i].name + "</td>"
												+ "<td>" + data[i].age + "</td>"
												+ "<td>" + data[i].salary + "</td>"
												+ "<td>" + hireDate + "</td>" 
												+ "<td>" + "<a href='update.html?id="+data[i].id+"'>"+"修改"+"</a>"+"<a href='employee.html?id="+data[i].id+"'onclick='formSub1( )'>" +"删除"+ "</a>"+"</td>"+
										"</tr>");	
							}tbody.innerHTML=str;						
						}
					})
				})
				
		function formSub1(){		
			var msg = "您真的确定要删除吗？";
			if (confirm(msg)==true){
			}else{
				alert("删除失败");
			return false;
			}
			}
	    /* 提示执行完后url带上id的值，自执行取id的值 再传	*/					
		(function my () {			
			var str = window.location.href;
			var num = str.indexOf("?");
			var id1 = str.substr(num + 1);
			var b = id1.indexOf("=");
			var id = id1.substr(b + 1);		
			$.ajax({
				data : {
					 'id' : id
				},
				async:false,
				type : "GET",
				dataType : 'json',
				url : "employee/delete",
				/* error : function(data) {
					alert("error:"+data);
				}, */
				success : function(data) {
					window.location.href="http://localhost:8080/springMvcAndMybatisAjax/employee.html";
				}})}())	
	</script>

</body>
</html>